<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>数据源</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../css/scroll-bar.css">
    <link rel="stylesheet" href="../css/sub-page.css">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../lib/nprogress/nprogress.css">
</head>

<body>
    <div class="ok-body">
        <!--面包屑导航区域-->
        <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>数据集管理</cite></a>
                <a><cite>集合源</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh"></i>
            </a>
        </div>
        <!--工具栏-->
        <okToolbar>
            <!--   <button class="layui-btn layui-btn-normal" id="batchEnabled">
                <i class="iconfont icon-shangsheng"></i>批量启用
            </button>
            <button class="layui-btn layui-btn-warm" id="batchDisabled">
                <i class="iconfont icon-web-icon-"></i>批量停用
            </button>
            <button class="layui-btn layui-btn-danger" id="batchDel">
                <i class="layui-icon layui-icon-delete"></i>批量删除
            </button> -->
            <!--    <button class="layui-btn layui-btn-sm" id="add">
                <i class="layui-icon">&#xe61f;</i>确认选取
            </button> -->
            <button class="layui-btn layui-btn-sm" id="back"><i class="layui-icon"></i>返回上级目录</button>
            <span>共有数据：<i id="countNum">0</i> 条</span>
        </okToolbar>
        <!--数据表格-->
        <table class="layui-hide" id="mytable" lay-filter="mytable"></table>
        <input class="layui-hide" id='id' value="">
    </div>
    <!--js逻辑-->
    <script src="../lib/layui/layui.js"></script>
    <script src="../lib/nprogress/nprogress.js"></script>
    <script>
        NProgress.start();
    window.onload = function () {
        NProgress.done();
    }
    layui.use(['element', 'table', 'form', 'jquery'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        table.render({
            elem: '#mytable',
            url: '/dataset/datasource',
            limit: 65535,
            cellMinWidth: 80, 
            page: true,
            id:'folderlist',
            where:{
                key:$('#id').val()
            },
            cols: [[
                {field: 'id', title: 'ID', width: 80},
                {field: 'name', title: '名称'},
                {field: 'path', title: '资源路径'},   
                {field: 'dstags', title: '标签'},      
                {field: 'description', title: '描述'},      
                {field: 'dstype', title: '类型',width:95,templet: '#typeTpl'},               
                {field: 'createat', title: '创建时间',sort: true}
            ]],
            done: function (res, curr, count) {
                $("#countNum").text(count);
                
            }
        });

        var active = {
            reload: function(){                
                //执行重载
                table.reload('folderlist', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where:{
                        key:$('#id').val()
                    }
                });
            }
        };   


        
        var rootpath=$('#id').val();
        var patharray=[rootpath];
         //监听行双击事件（单击事件为：rowDouble）
        table.on('rowDouble(mytable)', function(obj){
            var data = obj.data;
            if(data.dstype=='-2'){//文件夹
                layer.alert('文件夹不支持展开');
            }else{
                $('#id').val(data.id);
                patharray.push(data.id);
                //layer.alert(JSON.stringify(data));  
                active.reload();   
            }
                               
        });

        //监听行单击事件（单击事件为：rowDouble）
        /* table.on('row(mytable)', function(obj){
            //获取选中的数据行
            var checkStatus = table.checkStatus('folderlist');
            var data = checkStatus.data;

            layer.alert(JSON.stringify(data));
            console.log(data);
                
        }); */

         $("#back").click(function () {
            patharray.pop();
            var id=patharray.pop();
            $('#id').val(id);
            if(patharray.length==0){
                patharray.push(rootpath);
                $('#id').val(rootpath);
                $('#back').hide();
            }else{
                $('#back').show();
            }
            active.reload();   
        });
        

    })
</script>

    <script type="text/html" id="typeTpl">
        <a href="javascript:;" title="类型"  class="layui-btn layui-btn-xs {{ d.dstype== '1' ? 'layui-bg-green' : 'layui-bg-blue'}}">
                {{#  if(d.dstype == '-2'){ }}
                文件夹
              {{#  } }}
                {{#  if(d.dstype == 0){ }}
                数据集
              {{#  } }}
              {{#  if(d.dstype == 1){ }}
                文件系统
              {{#  } }}
             
           </a>
</script>
</body>

</html>